import * as Icons from '@element-plus/icons-vue'

// 菜单项类型定义
export interface MenuItem {
  id: string
  label: string
  icon?: string
  isUrl?: boolean
  path?: string
  children?: MenuItem[]
  active?: boolean
  mouseover?: boolean
  hidden?: boolean
  permission?: string[]
  parent?: MenuItem
}

// 定义YqPub类
export class YqPub {
  // 获取图标组件
  static GetIconComponent(iconName: string) {
    if (!iconName) return Icons.Share
    
    // 检查是否为图片URL路径
    const isImagePath = iconName.startsWith('/') || 
                       iconName.startsWith('../') || 
                       iconName.startsWith('./') || 
                       iconName.startsWith('http://') || 
                       iconName.startsWith('https://')
    
    if (isImagePath) {
      // 返回图片信息对象
      return {
        type: 'image',
        src: iconName
      }
    } else {
      // 处理element-plus/icons-vue组件
      console.log('Icon name:', iconName)
      
      // 将图标名称转换为PascalCase格式
      const convertToPascalCase = (iconName: string) => {
        if (!iconName) return ''
        return iconName
          .split('_')
          .map(word => word.charAt(0).toUpperCase() + word.slice(1))
          .join('')
      }
      
      const pascalCaseName = convertToPascalCase(iconName)
      console.log('PascalCase name:', pascalCaseName)
      
      // 尝试从Icons对象中获取图标组件
      const iconComponent = Icons[pascalCaseName as keyof typeof Icons]
      
      // 如果找到图标组件，则返回它
      if (iconComponent) {
        console.log(`Found icon: ${pascalCaseName}`)
        return iconComponent
      }
      
      // 如果找不到，则返回一个默认的图标组件
      console.log(`Icon '${iconName}' not found, using default icon`)
      return Icons.Share
    }
  }
}

// 导出命名组件和类
export default YqPub